package stud.cj.day15;
import java.util.Arrays;

public class ParamTransferDemo {
    public static void main(String[] args) {
        //相同为0,不同为1
        System.out.println(10 ^ 8);
        // 1 0 1 0
        // 1 0 0 0
        //---------
        // 0 0 1 0  => 2

        System.out.println(10 ^ 8 ^ 8);//10
        //0 0 1 0
        //1 0 0 0
        //-------
        //1 0 10   => 10

        //结论:一个数连续异或同一个数俩次是它自己本身.   ^ 简单的加密和解密操作


        int a = 10;
        int b = 20;

        //基本类型 - 值传递 - 将变量保存的数据赋值一份给方法的参数
        //想象成文件的拷贝.
        change(a,b);

        System.out.println("main-a:"+a);//10
        System.out.println("main-b:"+b);//20

        int[] arr1 = {1,2,3};
        int[] arr2 = {1,2,3};

        add(arr1,arr2);

        System.out.println("main-arr1->"+ Arrays.toString(arr1));//1,2,3
        System.out.println("main-arr2->"+ Arrays.toString(arr2));//11,12,13
    }

    private static void add(int[] arr1, int[] arr2) {
        //将arr2中的每个数字加10
        for (int i = 0; i < arr2.length; i++) {
            arr2[i] = arr2[i] + 10;
        }

        arr1 = arr2;

        System.out.println("add->"+ Arrays.toString(arr1));//11,12,13
        System.out.println("add->"+ Arrays.toString(arr2));//11,12,13
    }

    //交换俩个变量的值
    private static void change(int a, int b) {
        a = a ^ b;//a = 10 ^ 20
        b = a ^ b;//b = 10 ^ 20 ^ 20 = 10
        a = a ^ b;//a = 10 ^ 20 ^ 10 = 20

        System.out.println("change-a->"+a);//10
        System.out.println("change-b->b"+b);//20
    }
}
